Code:
#include <windows.h>
#include <stdio.h>
#include <Uxtheme.h> //for use the theme functions
#include <Vsstyle.h> //for use the BP_PUSHBUTTON or others const's
#include "Untitled2.h" //is for resource file
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
static TCHAR szAppName[] = TEXT ("RandRect") ;
HINSTANCE a;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
HWND hwnd ;
MSG msg ;
a=hInstance;
WNDCLASS wndclass ;
wndclass.style = 0 ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, "IDI_ICON");
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindowEx (WS_EX_CLIENTEDGE,szAppName, TEXT ("Random Rectangles"),
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
static HWND hButton;
static HINSTANCE hInstance = GetModuleHandle(NULL);
static HICON HandleIcon;
switch (iMsg)
{
case WM_DESTROY:
DestroyIcon(HandleIcon);
PostQuitMessage (0) ;
return 0 ;
//case WM_CTLCOLORBTN:
//return (LRESULT) GetStockObject (NULL_BRUSH);
case WM_CREATE:
//create the button
hButton=CreateWindowEx (0,"button", "H&ello \nmy mother",
WS_CHILD | WS_VISIBLE | BS_OWNERDRAW | BS_NOTIFY,
100, 100,100, 50,hwnd,NULL,hInstance, 0) ;
return 0;
case WM_KEYUP:
//exit the program
if(wParam==VK_ESCAPE)
{
DestroyWindow(hwnd);
}
return 0;
case WM_DRAWITEM:
//getting the Draw Item structure
LPDRAWITEMSTRUCT b;
b = (LPDRAWITEMSTRUCT) lParam;
//Getting the button visual theme(i get the xp style)
HTHEME hTheme;
hTheme = OpenThemeData(hButton, L"button");
//translate the LPDRAWITEMSTRUCT->itemState to DrawThemeBackground int id state
int c=0;
if(b->itemState & ODS_HOTLIGHT)
c=PBS_HOT;
else if (b->itemState & ODS_DEFAULT)
c=PBS_DEFAULTED;
else if (b->itemState & ODS_DISABLED)
c=PBS_DISABLED;
else if (b->itemState & ODS_SELECTED)
c=PBS_PRESSED;
else
c|=PBS_NORMAL;
//draw the button with right state
//the state is what the button action can draw to us(click,disable and others)
DrawThemeBackground(hTheme, b->hDC, BP_PUSHBUTTON, c, &b->rcItem, 0);
//getting and draw icon
HICON hicon;
hicon=LoadIcon(NULL,IDI_EXCLAMATION);
DrawIcon(b->hDC,3,0, hicon);
//before show the text, i need put it transparent(hide the text backcolor)
SetBkMode(b->hDC,TRANSPARENT);
//i can draw the text with prefix('&')
//the DT_EXPANDTABS is for show us the '\t' and others
DrawText(b->hDC,"&hello",-1,&b->rcItem,DT_EXPANDTABS| DT_CENTER);
return 0;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
}
i only see 1 problem: is showed the button face with windows xp visual style, instead windows 2000 visual style